<?php
@ob_start();
@session_start();
include("checkSession.php");
error_reporting (E_ALL ^ E_NOTICE);
require_once("../../includes/GPSFunction.php");

//require_once("User.php");

//	DB Connection
require_once("../../includes/config.inc.php"); 
require_once("../../includes/Database.class.php"); 
require_once("../../includes/pagination.php");

global $db;
$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); 
$db->connect(); 
//echo $_SERVER['HTTP_HOST'];
include("Util.php"); 
$util =  new Util();


$getfuelInfo = "SELECT count(*) as cnt FROM tb_deviceinfo WHERE di_userId = ".$_SESSION[userID]." and di_fuel=1";
$resfuelInfo = $db->query($getfuelInfo);
$recordfuelInfo = $db->fetch_array($resfuelInfo);

// Get User Information
$getUserInfo = "SELECT * FROM tb_userinfo,tb_clientinfo WHERE ui_accessFlag  = 1 AND ui_id  = ".$_SESSION[userID]." AND ci_id = ".$_SESSION[clientID];
$resUserInfo = $db->query($getUserInfo);

if($db->affected_rows > 0){
	$recordUserInfo = $db->fetch_array($resUserInfo);
	
	$_SESSION[client_type]  = $recordUserInfo[ci_clientType];
	//print_r($recordUserInfo);	
	if($recordUserInfo[ci_clientId]!=0)
	{
		$getResellInfo = "SELECT ci_clientName,ci_clientLogo,ci_footerText,ci_googleApiKey FROM tb_clientinfo WHERE ci_id = ".$recordUserInfo[ci_clientId];
		$resResellInfo = $db->query($getResellInfo);
		if($db->affected_rows > 0){
			$fetResellInfo = $db->fetch_array($resResellInfo);
			//print_r($fetResellInfo);
			//$_SESSION[GoogleMapApi] = $fetResellInfo[ci_googleApiKey];
			$clientLogo = $fetResellInfo[ci_clientLogo];
			$clientOrgName = $fetResellInfo[ci_clientName];
			$clientFooter = $fetResellInfo[ci_footerText];
		}
		else
		{
			$clientOrgName = $recordUserInfo[ci_clientName];
			$clientLogo = $recordUserInfo[ci_clientLogo];
			$clientFooter = $recordUserInfo[ci_footerText];
		}
	}
	else
	{
		$clientOrgName = $recordUserInfo[ci_clientName];
		$clientLogo = $recordUserInfo[ci_clientLogo];
		$clientFooter = $recordUserInfo[ci_footerText];
	}
	$welcomeTxt = '';
	if($recordUserInfo[ui_isAdmin] == 1)
	{
		$welcomeTxt = 'Admin';
	}
	elseif($recordUserInfo[ui_roleId])
	{
		
		$welcomeTxt = $util->getRoleNameOfUserByRoleId($recordUserInfo[ui_roleId]);
	}
	
}
else
{
	header("location:userLogout.php");
	exit;
}
//print_r($_SESSION);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $clientOrgName;?> :: GPS Application</title>
<link href="../../images/fav-icon.gif" rel="icon" />
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css" media="all">@import "../../css/timePicker.css";</style>
<link rel="stylesheet" href="../../css/themes/base/jquery.ui.all.css">

<script src="../../js/ajax.js" type="text/javascript"></script>
<script src="../../js/gen_validatorv31.js" type="text/javascript"></script>

<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="../../js/ui/jquery.ui.core.js"></script>
<script src="../../js/ui/jquery.ui.widget.js"></script>
<script src="../../js/ui/jquery.ui.datepicker.js"></script>
<script src="../../js/jquery.jeditable.js" type="text/javascript"></script>


<script type="text/javascript" src="../../js/jquery.layout.js"></script>
<script type="text/javascript" src="../../js/timePicker.js"></script>

<script type="text/javascript" src="../../js/highcharts.js"></script>
<script type="text/javascript" src="../../js/modules/exporting.js"></script>

<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="css/template.css" type="text/css"/>
<script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="../../js/pagination.js"></script>

<link rel="stylesheet" type="text/css" href="css/chromestyle4.css" />
<script type="text/javascript" src="js/chrome.js"></script>


<script type="text/javascript" src="js/autosuggest.js"></script>

<script language="javascript">
function userLogout()
{
	location.href = 'userLogout.php';
}
function searchDevice(did)
{
	if(did)
	document.searchForm.submit();
}
function backToAdmin(sid,type)
{
	document.frmRedirect.txtSuperID.value = sid;
	document.frmRedirect.adminType.value = type;
	document.frmRedirect.action = "ajax_server.php";
	document.frmRedirect.submit();
}
$(function() {
	$( "#index_date" ).datepicker({
		changeMonth: true,
		changeYear: true,
		maxDate: 0,
		showOn: "button",
		buttonImage: "images/calender.gif",
		buttonImageOnly: true,
		dateFormat : "dd MM yy"
	});
});
</script>
<!-- CSS -->
<style>
</style>

</head>

<body>

<div class="wrapper"><!-- wrapper div START here  -->	
	<div class="headerarea"><!-- Headerarea div START here -->
   
    	<div class="toparea"><!-- toparea div start here -->
        	 <div class="left"><a href=""><img src="../client_logo/<?php echo $clientLogo;?>" width="100%" height="45" /></a></div>
            <div class="right">
                <p><strong>Welcome</strong> : <span class="ui-widget-header"> <?php echo ucfirst($recordUserInfo[ui_firstname]." ".$recordUserInfo[ui_lastname])." (".$recordUserInfo[ci_clientName].")";?></span>  | 
                <?php if($recordUserInfo[ci_clientType] == "Reseller" && $recordUserInfo[ui_isAdmin] == "1")  { ?>
                <a class="ui-state-error-text" href="">Profile</a> 
                <?php } else { ?>
                <a class="ui-state-error-text" href="">Profile</a> 
                <?php } ?>
                | <a class="ui-state-error-text" href="">Change password</a> 
                | <a class="ui-state-error-text" href="#" onclick="javascript:userLogout();">Logout</a>
                | <span class="" id>Today : <?php echo date("d F Y, h:i A");?></span>
                 <?php if(isset($_SESSION[superID]) && $_SESSION[superID] !="") {?>
                | <a class="ui-state-error-text" href="#" onclick="javascript:backToAdmin('<?php echo $_SESSION[superID];?>','S');">Back To Admin</a>
                <?php } ?>
                <?php if(isset($_SESSION[ResellID]) && $_SESSION[ResellID] !="") {?>
                | <a class="ui-state-error-text" href="#" onclick="javascript:backToAdmin('<?php echo $_SESSION[ResellID];?>','R');">Back To Admin</a>
                <?php } ?>
                <p>
            </div>
            <!--<div class="right"><span class="datearea">
                	style="border:0px; color:#0099FF; font:Arial, Helvetica, sans-serif 12px bold;" id="index_date" class="" readonly="true"/></span>
                    <a href="#">[+] Settings</a><a href="#">[+] Sitemap</a><a href="#">About Us</a><a href="#">[+] Feedback</a></div>
            
        <div class="clear"></div>    -->
        </div><!-- toparea div END here -->
        
        
        
        <div class="logo_login_area"><!-- Logo and Login div start here -->
        	
            
            <div class="menu_place_area" id="chromemenu"><!-- menuarea div end here -->
                <ul class="menu">
                    <li><a href="">Home</a></li>  
                    
                    <?php if($recordUserInfo[ci_clientType] == "Reseller" && $recordUserInfo[ui_isAdmin] == "1") { ?>
                    <li><a href="#" rel="dropmenu1">Account</a></li>
                    <!--li><a href="#" rel="dropmenu9">Reports</a></li>-->
                    <?php } ?>
                    
                    <?php if(($recordUserInfo[ci_clientType] == "Client") && $recordUserInfo[ui_isAdmin] == "1") { ?>
                    <li><a href="#" rel="dropmenu2">Management</a></li>    
					<!--<li><a href="#" rel="dropmenu7">Gen Pro</a></li>-->
                    <li><a href="#" rel="dropmenu3">Reports</a></li>
                    <li><a href="#" rel="dropmenu6">Graphs</a></li>
                    <li><a href="#" rel="dropmenu4">GeoFence</a></li>	
                    <?php } else if( ($recordUserInfo[ci_clientType] == "Client") && $recordUserInfo[ui_isAdmin] == "0" && $recordUserInfo[ui_roleId] == "1") {?>
                    <li><a href="#" rel="dropmenu3">Reports & Graphs</a></li>
                    <?php } ?>
                    
                    <li><a href="../tr" class="top_link" target="_blank">Map</a></li>
                    <li><a href="" class="top_link">Help</a></li>
                </ul>
            <div class="clear"></div>
	        </div><!-- menuarea div end here -->
    		
           
            <div class="search_area">
             <?php if(($recordUserInfo[ci_clientType] == "Client") && $recordUserInfo[ui_isAdmin] == "1") { ?>
            	<div class="search_input">
                	<input type="text" size="20" class="search_text" value="" id="inputString" name="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
                    <input type="button" value="Search" name="srcDevDrop" id="srcDevDrop" class="search_btn" onclick="searchDevice(document.getElementById('inputString').value)" />
                    <div class="suggestionsBox" id="suggestions" style="display: none;">
                        <img src="images/upArrow.png" style="position: relative; top: -18px; left: 100px;" alt="upArrow" />
                        <div class="suggestionList" id="autoSuggestionsList"></div>
                    </div>
                </div>
           	<?php } ?>		
        	</div>
        </div><!-- Logo and Login div end here -->
        <!--1st drop down menu -->                                                   
        <div id="dropmenu1" class="dropmenudiv">
        	<a href="">Client</a>
            <a href="">Reseller</a>
            <!--<a href="?ch=viewSimcard">Sim Card</a>-->
        </div>
         <div id="dropmenu9" class="dropmenudiv">
       	   <a href="">Subscription Reports</a>
       	   <a href="">Simcard Reports</a>        </div>
        
        <!--2nd drop down menu -->                                                
        <div id="dropmenu2" class="dropmenudiv" style="width: 150px;">
       	  <a href="">My User</a>
          <a href="">My Device</a>
		  <a href="">My Contacts</a>
          <a href="">My Alerts</a>
            <?php if(($recordUserInfo[ci_clientType] == "Reseller") && $recordUserInfo[ui_isAdmin] == "1") { ?>
          <a href="">Send SMS</a>
            <?php } ?>
        </div>
        
        <!--3rd drop down menu -->                                                   
        <div id="dropmenu3" class="dropmenudiv" style="width: 150px;">
       	  <a href="">Trip Report</a>
          <a href="">Master Report</a>
          <a href="">Geofence Report</a>
          <a href="">Stop Report</a>
          <a href="">Distance Report</a>
            <!--<a href="?ch=ac">AC Report</a>
            <a href="?ch=ignition">Ignition Report</a>-->
          <a href="">Custom Report</a>
			<?php if($recordfuelInfo[cnt]>='1'){?>
          <a href="">Fuel Report</a>
			<?php }?>
          <a href="">Idle Report</a>
          <a href="">SMS Alert</a>
          <a href="">Mail Alert</a>      </div>
<div id="dropmenu6" class="dropmenudiv" style="width: 150px;">

      <a href="">Speed Graph</a>
      <a href="">Altitute Graph</a>
      <a href="">Fuel Graph</a>
      <a href="">Mileage Graph</a>      </div>
       
        <div id="dropmenu4" class="dropmenudiv" style="width: 150px;">
        	<a href="../tr/geofence/geocode.php" target="_blank">Create Circle</a>
            <a href="../tr/geofence/polygon.php" target="_blank">Create Polygon</a>
          <a href="">Assign</a>        </div>
        
         <div id="dropmenu5" class="dropmenudiv">
       	   <a href="" class="fly">Employee</a>        </div>

		 <!--7th  Gen set menu -->                                                
        <div id="dropmenu7" class="dropmenudiv" style="width: 150px;">
        	<a href="#" onclick="javascript:alert('Report not available');">LLOP</a>
            <a href="#" onclick="javascript:alert('Report not available');">HCT</a>
			<a href="#" onclick="javascript:alert('Report not available');">HWT</a>
            <a href="#" onclick="javascript:alert('Report not available');">DG RUN</a>
            <a href="#" onclick="javascript:alert('Report not available');">Mains RUN</a>
			<a href="#" onclick="javascript:alert('Report not available');">Fuel</a>        </div>
        
        
    </div><!-- headerarea div END here -->
	<div class="pagearea"><!-- pagearea div start here -->
    	
        <!-- <div class="leftarea"><div class="ui-layout-west left_panel">left Panel Div Start here -->
        
        	<!--<div class="leftmenu">
            	<ul>
                	<li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                    <li>AP 31 AJ 0502XX</li>
                </ul>
            
            
            </div>-->
        
        
         <!--</div>left Panel Div END here -->
        <!-- <div class="ui-layout-center content_panel">CONTENT Panel Div Start here -->
            <!--<div class="title_area"> tilte_area div start here
       			<h1></h1>
            </div>   tilte_area div END here-->
             <div align="center" id="mainAreaInternal">
            <?php			
			  switch($_GET[ch]) 
			  {
 			  	case 'help':
				   include("help.html");
				   break; 
				case 'customReport':
				   include("../report/customReport.php");
				   break; 
				case 'sendSMS':
				   include("sendSMS.php");
				   break;  
				case 'viewFullDevice':
				   include("viewFullDevice.php");
				   break;
				case 'mailreport':
				   include("../report/mailreport.php");
				   break;
				case 'smsreport':
				   include("../report/smsreport.php");
				   break;
				case 'mapReport':
				   include("../report/mapReport.php");
				   break;
				case 'mileage':
				   include("../report/mileage.php");
				   break;
				case 'myalerts':
				   include("myalerts.php");
				   break;
				case 'deviceParams':
					 include("mydeviceparams.php");
					break;
				case 'fuel':
				   include("../report/fuelConsumeReport.php");
				   break;
				   case 'fuel_graph':
				   include("../report/fuelConsumeGraph.php");
				   break;
				case 'viewAssignGeo':
				   include("viewAssignGeo.php");
				   break;
				case 'viewContact':
				   include("viewContact.php");
				   break;
			  	case 'insurance':
				   include("insurance.php");
				   break;
			  	case 'manageDevice':
				   include("manageDevice.php");
				   break;
				case 'assignGeofence':
				   include("assignGeofence.php");
				   break;
				case 'geofence':
				   include("../report/geofence.php");
				   break;
				case 'altitute':
				   include("../report/altitute.php");
				   break;
				 
				case 'speed':
				   include("../report/speed.php");
				   break;
                case 'idlereport':
				  include("../report/idlereport.php");
				break;
				
				case 'ac':
				  include("../report/acreport.php");
				break;
				case 'ignition':
					include('../report/igreport.php');
				break;
				case 'distance':
				   include("../report/distance.php");
				   break;
				case 'stop':
				   include("../report/stop.php");
				   break;
				case 'daily':
				   include("../report/daily.php");
				   break;
				case 'viewResellerSubscription':
				   include("viewResellerSubscription.php");
				   break;
			  	case 'addResellerSubscription':
				   include("addResellerSubscription.php");
				   break;
				 case 'viewReseller':
				   include("viewReseller.php");
				   break;
			  	case 'addReseller':
				   include("addReseller.php");
				   break;
			  	case 'Reseller':
				   include("Reseller.php");
				   break;
				case 'mySubscription':
				   include("mySubscription.php");
				   break;
				case 'Subscription':
				   include("Subscription.php");
				   break;
				case 'addSubscription':
				   include("addSubscription.php");
				   break;
				case 'viewSubscription':
				   include("viewSubscription.php");
				   break;
				case 'addClientDevice':
				   include("addClientDevice.php");
				   break;
				case 'viewClientDevice':
				   include("viewClientDevice.php");
				   break;
				case 'Admin':
				   include("Admin.php");
				   break;
			  	case 'addAdmin':
				   include("addAdmin.php");
				   break;
			  	case 'viewAdmin':
				   include("viewAdmin.php");
				   break;
			  	case 'viewClient':
				   include("viewClient.php");
				   break;
			  	case 'Client':
				   include("Client.php");
				   break;
				case 'addClient':
				   include("addClient.php");
				   break;
			  	case 'profileAdmin':
				   include("profileAdmin.php");
				   break;
				case 'change_pass':
				  include("change_password.php");
                 break;
			  	case 'profile':
				   include("profile.php");
				   break;
			  	case 'groupMembers':
				   include("groupMembers.php");
				   break;
			  	case 'Group':
				  include("Group.php");
				  break;
			    case 'viewGroup':
				  include("viewGroup.php");
				  break;
			  	case 'Device':
				  include("Device.php");
				  break;
			  	case 'addDevice':
				  include("addDevice.php");
				  break;
			  	case 'viewDevice':
				  include("viewDevice.php");
				  break;
			  	case 'viewUser':
				  include("viewUser.php");
				  break;
			  	case 'status':
				  include("status.php");
				  break;
			  	case 'User':
				  include("User.php");
				  break;
				case 'home':
				  //include("home.php");
				  ?>
				 <iframe id="liveFrame" src ="home_test.php" scrolling="no" style="border:#ebebeb solid 0px; text-align:center" frameborder="0" height="550px" width="100%"></iframe>
                <?php
				  break;
				case 'addUser':
				  include("addUser.php");
				  break;
				default:
				  //include("viewClient.php");
				  ?>
				<iframe id="liveFrame" src ="home.php" scrolling="no" style="border:#ebebeb solid 0px; text-align:center" frameborder="0" height="550px" width="100%"></iframe>
                <?php
				  break;
			  }
			?>
        </div><!-- CONTENT Panel Div END here -->
        <div class="clear"></div>
    </div><!-- Pagearea div end here -->
    
    <div class="clear"></div>
    <div class="footerarea"><!-- footerarea div START here -->
    	<span class="left">&nbsp;</span>
        <span class="right" style="text-align:right;"><?php echo $clientFooter;?><!--<a href="#">Link one</a> | <a href="#">Link one</a> | <a href="#">Terms &amp; Conditions</a>--></span>
    </div><!-- Footerarea div END here -->
</div><!-- wrapper div END here -->


<form name="searchForm" id="searchForm" method="post" action="">
	<input type="hidden" name="txtDeviceId" id="txtDeviceId" />
</form>
<form name="frmRedirect" id="frmRedirect" method="post">
	<input type="hidden" name="txtSuperID" id="txtSuperID" />
    <input type="hidden" name="adminType" id="adminType" />
</form>
<div class="clear"></div>
</body>
</html>
<script type="text/javascript">

cssdropdown.startchrome("chromemenu")

</script>
<?php

$db->close();

?>